#coding=utf-8
from rest_framework import serializers
from .models import Navigation, HouseType, HouseBuilding, HouseBuildingImage, DesignerJob, Designer, HouseStyle, DesignerGoodStyle, CaseImage, Case, Banner, Article, GlobalActivity, FurnitureType, FurnitureBrand, Furniture, FurnitureImage
from system.serializers import CompanySerializer, RegionSerializer, UserProfileSerializer

class NavigationSerializer(serializers.ModelSerializer):
    company = CompanySerializer(required=False)
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    class Meta:
        model = Navigation
        fields = '__all__'

class HouseTypeSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = HouseType
        fields = '__all__'

class HouseBuildingImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = HouseBuildingImage
        fields = '__all__'

class HouseBuildingSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    region = RegionSerializer(required=False)

    images = serializers.SerializerMethodField()
    def get_images(self, obj):
        return HouseBuildingImageSerializer(obj.images, many=True)

    class Meta:
        model = HouseBuilding
        fields = '__all__'

class DesignerJobSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = DesignerJob
        fields = '__all__'

class HouseStyleSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = HouseStyle
        fields = '__all__'

class DesignerGoodStyleSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    style = HouseStyleSerializer(required=False)

    class Meta:
        model = DesignerGoodStyle
        fields = '__all__'

class DesignerSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    job = DesignerJobSerializer(required=False)

    goodstyles = serializers.SerializerMethodField()
    def get_goodstyles(self, obj):
        return DesignerGoodStyleSerializer(obj.goodstyles, many=True)

    class Meta:
        model = Designer
        fields = '__all__'

class CaseImageSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = CaseImage
        fields = '__all__'

class CaseSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    house = HouseBuildingSerializer(required = False)
    housetype = HouseTypeSerializer(required = False)
    housestyle = HouseStyleSerializer(required = False)
    designer = DesignerSerializer(required = False)

    images = serializers.SerializerMethodField()
    def get_images(self, obj):
        return CaseImageSerializer(obj.images, many=True)

    class Meta:
        model = Case
        fields = '__all__'


class BannerSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = Banner
        fields = '__all__'


class ArticleSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    writor = UserProfileSerializer(required = False)
    reviewer = UserProfileSerializer(required = False)
    review_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = Article
        fields = '__all__'


class GlobalActivitySerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = GlobalActivity
        fields = '__all__'

class FurnitureTypeSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = FurnitureType
        fields = '__all__'


class FurnitureBrandSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = FurnitureBrand
        fields = '__all__'

class FurnitureImageSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = FurnitureImage
        fields = '__all__'

class FurnitureSerializer(serializers.ModelSerializer):
    updated_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    created_at = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    ftype = FurnitureTypeSerializer(required = False)
    brand = FurnitureBrandSerializer(required = False)

    images = serializers.SerializerMethodField()
    def get_images(self, obj):
        return FurnitureImageSerializer(obj.images, many=True)

    class Meta:
        model = Furniture
        fields = '__all__'


